package com.example.demo.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @author admin
 * @version 1.0 <br/>
 * <p style="font-family:SimSun;font-weight:bold">时间:<br/>2021/12/2 14:39</p>
 * @description
 */
@Component
public class ApplicationContextUtils implements ApplicationContextAware {
    private static ApplicationContext context=null;
    public static <T> T getBean(Class<T> type) {
        return context.getBean(type);
    }
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        if (context == null) {
            context = applicationContext;
        }

    }
}
